/*
 * Copyright (c) 2012 Supin P Surendran <supinps@gmail.com>.
 *
 * This file is part of InventoryMan.
 *
 * InventoryMan is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * InventoryMan is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with licenseTest.  If not, see <http ://www.gnu.org/licenses/>.
 *
 */
package InventoryMan;

/**
 *
 * @author supinps
 */
public class ServerConfig extends javax.swing.JInternalFrame {

    /** Creates new form ServerConfig
     * @param pref server parameters
     */
    public ServerConfig(java.util.prefs.Preferences pref) {
        serverPreference=pref;
        initComponents();
        if(serverPreference.get("ip", null)!=null) {
            TxtIp.setText(serverPreference.get("ip", null));
            TxtPort.setText(serverPreference.get("port", null));
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        TxtIp = new javax.swing.JTextField();
        TxtPort = new javax.swing.JTextField();
        BnSave = new javax.swing.JButton();
        BnCancel = new javax.swing.JButton();

        setTitle("Server Configuration");
        setFrameIcon(new javax.swing.ImageIcon(getClass().getResource("/Resources/icon_small.png"))); // NOI18N

        jLabel1.setText("Server IP     :");

        jLabel2.setText("Server Port :");

        BnSave.setText("Save");
        BnSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BnSaveActionPerformed(evt);
            }
        });

        BnCancel.setText("Cancel");
        BnCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BnCancelActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(BnSave, javax.swing.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(BnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(TxtPort, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 165, Short.MAX_VALUE)
                    .addComponent(TxtIp, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 165, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(TxtIp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(TxtPort, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(BnCancel)
                    .addComponent(BnSave))
                .addContainerGap(24, Short.MAX_VALUE))
        );

        getAccessibleContext().setAccessibleParent(this);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void BnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BnSaveActionPerformed
        serverPreference.put("ip", TxtIp.getText());
        serverPreference.put("port", TxtPort.getText());
        this.dispose();
    }//GEN-LAST:event_BnSaveActionPerformed

    private void BnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BnCancelActionPerformed
        this.dispose();
    }//GEN-LAST:event_BnCancelActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BnCancel;
    private javax.swing.JButton BnSave;
    private javax.swing.JTextField TxtIp;
    private javax.swing.JTextField TxtPort;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    // End of variables declaration//GEN-END:variables

    private java.util.prefs.Preferences serverPreference;
}
